<template>
	<view class="content">
		<view class="full" @click="closeFull"></view>
		<view class="login-out">
			<view class="user ac">
				<image class="photo" src="/static/img/index-icon2.png" v-if="user.avatar != ''"></image>
				<image class="photo" src="baseUrl+user.avatar" v-else></image>
				<view v-if="userInfo.name"><b>{{userInfo.name}}</b></view>
				<br />
				<view v-if="major&&false" @click="checkedMajor"><b>{{major}}</b></view>
				<!-- <view v-if="userInfo.phone"><b>电话号码：{{user.phone}}</b></view> -->
				<!-- <view v-if="userInfo.mobilephone"><b>手机号码：{{user.mobilephone}}</b></view> -->
			</view>
			<view class="controller">
				<view v-if="false" class="text">切换专业<view class="fr" @click="show_major = !show_major">
						<image class="arrow" src="/static/img/arrow.png"></image>
					</view>
				</view>
				<view v-if="false" class="majorClass" v-show="show_major"><text>专业信息</text>
					<u-radio-group :wrap="false" v-model="checkedValue" @change="checkboxGroupChange" shape='square'>
						<u-radio v-for="(item, index) in majorList" :key="item.name"
							:name="item.name">{{ item.name }}</u-radio>
					</u-radio-group>

				</view>
				<view class="text">推送设置<view class="fr" @click="show_switch = !show_switch">
						<image class="arrow" src="/static/img/arrow.png"></image>
					</view>
				</view>
				<view class="text" v-show="show_switch">是否推送<view class="fr">
						<u-switch v-model="checked" @change="onChange"></u-switch>
						<!-- <van-switch :checked="checked" @change="onChange" /> -->
					</view>
				</view>
				<view class="text" @click="clearData">清空缓存<view class="fr">
						<image class="arrow" src="/static/img/arrow.png"></image>
					</view>
				</view>
				<view @click="checkUpdate('')" class="text">检查新版本<view class="fr">
						<!-- {{version}} -->
						<view class="versionClass">
							<!-- <text style="padding-right: 10px;color:#fa">新版本</text> -->
							<image class="arrow" src="/static/img/arrow.png"></image>
						</view>
					</view>
				</view>
				<view class="text" @click="jumpUrl('/pages/system/about/index')">关于我们<view class="fr">
						<image class="arrow" src="/static/img/arrow.png"></image>
					</view>
				</view>
			</view>
			<view class="btn"><button class="default-btn" @click="quit"><b>退出</b></button></view>
		</view>

		<!-- 	<zy-update theme="green" ref="ZyUpdate" @showupdateTips='showupdateTips' @changeUpdate="changeUpdate"
			:h5preview="true" oldversion="1.1.3" :autocheckupdate="false" :appstoreflag="false"
			:updateurl="update_url"></zy-update> -->
	</view>
</template>

<script>
	import Vue from 'vue'
	import ZyUpdate from '../../uni_modules/zy-upgrade-master/zy-upgrade.vue'
	import {
		mapState
	} from "vuex";
	// Get_App_Version
	import {
		WORK_CONTROLLER
	} from "../../api/pms";
	export default {
		props: ['user'],
		components: {
			ZyUpdate
		},
		computed: {
			...mapState([
				"userInfo",
			]),
		},
		mounted() {
			console.log('userInfo', this.userInfo)
			// this.checkUpdate('auto')
			this.checkedMajor()
		},
		data() {
			return {
				checked: true,
				show_switch: false,
				version: "1.1.3",
				update_url: '',
				major: '电务,信号,通信',
				show_major: false,
				checkedValue: '',
				majorList: [{

				}]
			}
		},
		methods: {
			checkboxGroupChange(val) {
				console.log('major-val',val)
			},
			checkedMajor() {
				this.major.split(',').forEach((item, index) => {
					this.majorList[index] = {
						name: item
					}
					this.major = this.majorList[0].name
					this.checkedValue =  this.major
				})
			},
			changeUpdate(value) {

			},
			checkUpdate(param) {
				// this.update_url = this.$store.state.baseUrl + WORK_CONTROLLER.Get_App_Version
				// console.log('this.update_url', this.update_url)
				// this.$nextTick(() => {
				// 	this.$refs.ZyUpdate.check_update(param)
				// })
				this.$emit("showCheckupdata")
			},
			showupdateTips(flag) {
				if (flag == 0) {
					uni.showModal({
						title: '提示',
						content: "已经是最新版本"
					})
					// uni.showModal({
					// 	title:"已经是最新版本",
					// 	icon:"none"
					// })
				}
			},
			closeFull() {
				this.$emit('closeFull');
			},
			jumpUrl(url) {
				this.closeFull();
				uni.navigateTo({
					url: url
				});
			},
			onChange(bol) {
				// this.checked = bol == true ? false : true;

				// 需要手动对 checked 状态进行更新
				// this.setData({ checked: detail });
				this.$emit('togglePush', bol);
			},
			quit() {
				// let obj = {
				// 	userid: this.getUserId()
				// };
				// this.fetch('Get',this.$store.state.baseEmerUrl+'/logout',{}).then((res)=>{
				// 	console.log("输出退出登录返回数据：",res);
				// if (res.returnCode == 1) {
				uni.showToast({
					title: '成功退出',
					icon: 'none'
				});

				uni.setStorageSync('token', '');
				uni.setStorageSync('userId', '');
				// uni.setStorageSync('username', '');
				uni.setStorageSync('userInfo', '');
				this.$store.state.userInfo = {};
				this.$store.state.menuOrderId = '';
				// uni.clearStorageSync();
				this.closeFull();
				setTimeout(() => {
					uni.reLaunch({
						url: '/pages/system/login/index'
					});
				}, 500);
				// 	}else{
				// 		uni.showToast({title:res.message,icon:'none'})
				// 	}
			},
			clearData() {
				let that = this;
				uni.showModal({
					title: '提示',
					content: '确定清除缓存吗?',
					confirmText: '立即清除',
					success(res) {
						if (res.confirm) {
							uni.clearStorageSync();
							uni.showToast({
								title: '清除成功'
							})
							that.closeFull()
							setTimeout(() => {
								uni.navigateTo({
									url: '/pages/system/login/index'
								});
							}, 500)
						}
					}
				})
			}
		}
	}
</script>

<style scoped>
	.majorClass {
		display: flex;
		flex-direction: row;
		border-bottom: 1px solid #F1F1F1;
		padding: 11px 0;
		justify-content: space-between;
		align-items: center;
	}

	.login-out>.user {
		margin-bottom: 40px;
		color: #3E3A39;
	}

	.login-out>.user>.photo {
		width: 68px;
		height: 68px;
		border-radius: 50%;
		margin-bottom: 10px;
	}

	.login-out>.controller {
		padding-left: 26px;
	}

	.login-out>.controller>.text {
		line-height: 50px;
		font-size: 14px;
		color: #3E3A39;
		border-bottom: 1px solid #F1F1F1;
		padding-right: 25px;
	}

	.arrow {
		width: 7px;
		height: 12px;
	}

	.btn {
		margin-top: 20vh;
	}

	.default-btn {
		width: 164px;
		margin: 0 auto;
	}

	.u-switch {
		vertical-align: middle;
	}
</style>